package org.jiuling.aliyun.oss.spring.config;

import org.jiuling.aliyun.config.AliYunConfig;
import org.jiuling.aliyun.oss.AliYunOss;
import org.jiuling.aliyun.oss.config.AliYunOssConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 阿里云OSSbean配置
 * @author 紫灵
 * @date 2022年10月09日 16时39分18秒
 */
@Component
@Configuration
public class AliYunOssBeanConfig {

    public final AliYunConfig aliYunConfig;

    public AliYunOssBeanConfig(AliYunConfig aliYunConfig) {
        this.aliYunConfig = aliYunConfig;
    }

    @Bean
    @ConfigurationProperties(prefix = "jiu-ling.aliyun.oss")
    public AliYunOssConfig aliYunOssConfig(){
        AliYunOssConfig aliYunOssConfig = new AliYunOssConfig();
        aliYunOssConfig.setAliYunConfig(aliYunConfig);
        return aliYunOssConfig;
    }

    @Bean
    public AliYunOss aliYunOss(){
        return new AliYunOss(aliYunOssConfig());
    }


}
